//app.js
App({
  onLaunch: function () {
    // 加载缓存中的skin
    this.getSkin()
  },

  globalData: {
    userInfo: null,
    skinConfig: {
      'skin-normal': { backgroundColor: '#005CAC', frontColor: '#ffffff' },
      'skin-light': { backgroundColor: '#FAFAFA', frontColor: '#000000' },
    },
    skin: 'skin-normal' // 当前主题
  },

  getSkin() {
    wx.getStorage({
      key: 'skin',
      success: res => {
        console.log()
        if (res.data) {
          this.globalData.skin = res.data
        }
      }
    })
  },

  saveSkin() {
    wx.setStorage({
      key: 'skin',
      data: this.globalData.skin
    })
  },

  // 设置头部
  setNavBar() {
    const { skin, skinConfig } = this.globalData
    const { frontColor, backgroundColor } = skinConfig[skin]
    wx.setNavigationBarColor({
      frontColor,
      backgroundColor
    })
  }
})